package com.my.xinyidaixi.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.my.xinyidaixi.Activity.ZongHe_WebView;
import com.my.xinyidaixi.Adapter.GoodsAdapter;
import com.my.xinyidaixi.DataBase.Bean.Advlist;
import com.my.xinyidaixi.DataBase.Model.Over_UserModer;
import com.my.xinyidaixi.DataBase.Model.UserModel;
import com.my.xinyidaixi.Globe.MyApplication;
import com.my.xinyidaixi.Interface.Goods_interface;
import com.my.xinyidaixi.Model.GoodsItem;
import com.my.xinyidaixi.Overwrite.OverGridView;
import com.my.xinyidaixi.R;
import com.my.xinyidaixi.Util.CacheSave;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * Created by zw on 2017/6/6.
 */
public class jianxifragment extends Fragment
{
    private Context context= MyApplication.getInstance();
    private  ImageView mRollViewPager;
    private View view;
    private OverGridView goodsitem;
    private GoodsAdapter goodsAdapter;
    private ArrayList<GoodsItem> datalist;
    private DecimalFormat df;
    private CacheSave cacheSave=new CacheSave();
    private UserModel model=new Over_UserModer();

   // private Goods_selectedList_interface goods_selectedList_interface;

    private Goods_interface goods_interface;
    private ImageView image;
    private String adv_url;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
    {

        view = inflater.inflate(R.layout.jianxifragment_layout,container,false);
        df = new DecimalFormat("#.00");
        initdata();
        return view;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        goods_interface= (Goods_interface) context;
    }

    public void initdata()
    {
        image = (ImageView) view.findViewById(R.id.jianxi_adb);
        image.setScaleType(ImageView.ScaleType.FIT_XY);
        String url="";
        ArrayList<Advlist> item=model.get_advlist();
        for(int i=0;i<item.size();i++)
        {
            if(item.get(i).getAdv_id().equals("6"))
            {
                url=item.get(i).getAdv_img_url(); //地址url回头再获取
                adv_url=item.get(i).getAdv_url();
                cacheSave.finalBitmap(image,url);
                break;
            }
        }

        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), ZongHe_WebView.class);
                intent.putExtra("url",adv_url);
                startActivity(intent);
            }
        });


       /* FinalBitmap finalBitmap = FinalBitmap.create(context);
        *//*finalBitmap.configBitmapLoadThreadSize(1);//定义线程数量*//*
        finalBitmap.configDiskCachePath(cacheSave.getCachePath()+ "/imageCache"); //设置缓存目录
        finalBitmap.configDiskCacheSize(1024 * 1024 * 10);//设置缓存大小
        finalBitmap.configLoadfailImage(R.mipmap.ic_launcher);//设置加载图片
        finalBitmap.display(image,url);*/

        goodsitem = (OverGridView) view.findViewById(R.id.GridView_goodsitem);

        datalist=GoodsItem.getGoodlist();

        goodsAdapter=new GoodsAdapter(datalist,context);

        goodsAdapter.huidiao_Goods_interface(goods_interface);//接口开始回调

        goodsitem.setAdapter(goodsAdapter);

        goods_interface.goods_adapter(goodsAdapter);


       /* jianxifragment jianxi=new jianxifragment();
        Bundle bundle=new Bundle();
        bundle.putSerializable("jianxi",datalist);
        jianxi.setArguments(bundle);
        getFragmentManager().beginTransaction().commit();*/
    }

}
